<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>回执-监狱</title>
    <link href="/static/css/main-page/g-reset.css" rel="stylesheet" type="text/css" />
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <style>
        body {
            height:auto;
        }
        td.discell {
            text-align:right;
            width:100px;
        }
        .dialog-box {
            padding:10px 20px;
            overflow:hidden;
        }
        .dialog-box > li {
            width:80%;
            float:left;
            margin:5px 0;
        }
        .dialog-box > li.currentUser-wrap {
            float:right;
        }
        .dialog-box > li > div {
            position:relative;
        }
        .dialog-box > li.currentUser-wrap > div {
            text-align:right;
        }
        .send-time {
            font-size:12px;
            line-height:18px;
            color:#919191;
            padding:0 10px;
        }
        .dialog-box > li > ul {
            float:left;
            background:#DCDFE6;
            color:#000;
            position:relative;
            padding:10px;
            max-width:380px;
            -webkit-border-radius:5px;
            -moz-border-radius:5px;
            border-radius:5px;
        }
        .dialog-box > li.currentUser-wrap > ul {
            float:right;
            background:#4A89FD;
            color:#fff;
            position:relative;
        }
        .dialog-box > li > ul:before {
            content:"";
            position:absolute;
            top:10px;
            left:-10px;
            height:0;
            width:0;
            border:5px solid #DCDFE6;
            border-left-color:transparent;
            border-top-color:transparent;
            border-bottom-color:transparent;
        }
        .dialog-box > li.currentUser-wrap > ul:before {
            content:"";
            position:absolute;
            top:10px;
            left:100%;
            height:0;
            width:0;
            border:5px solid #4A89FD;
            border-right-color:transparent;
            border-top-color:transparent;
            border-bottom-color:transparent;
        }
    </style>
</head>
<body>
<form id="form1" method="post" style="height:100%;width: 100%;overflow-x: auto;overflow-y: auto;">
    <!-- 用户 编辑框START-->
    <div id="editform" class="form mini-fit" style="margin-bottom: 140px;overflow-y: auto;height: 280px">
        <#--唯一标识id-->
        <input name="id" id="id" class="mini-hidden" style="width: 100%;" value="${id!''}" readonly />
        <#--罪犯编号-->
        <input name="priNum" id="priNum" class="mini-hidden" style="width: 100%" value="${priNum!''}" readonly />
        <ul class="dialog-box">
        </ul>

    </div>
    <div style="position: absolute;bottom:0;width:100%;height: 150px;border-top:1px solid #dfdfdf;text-align: center">
        <table style="height: 100%;width:100%">
            <#if level=='01'>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>监所联系人：</td>
                    <td width="100px">
                        <input  class="mini-textbox" required="true" emptyText="请输入监所联系人" id="Receiver" name="Receiver"
                               value="${username!''}" />
                    </td>
                </tr>
                <tr>
                    <td class="discell">监所手机号码：</td>
                    <td>
                        <input  class="mini-textbox"  emptyText="请输入手机号码" id="ReceiverPhone" name="ReceiverPhone"
                                onblur="checkPhone(2)" value="${phone!''}" />
                    </td>
                    <td class="discell">监所固话：</td>
                    <td width="100px">
                        <input class="mini-textbox"  emptyText="请输入固定电话" id="ReceiverTel" name="ReceiverTel"
                               onblur="checkPhone(1)" value="${tel!''}" />
                    </td>
                </tr>
            <#elseif level=='02'>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>看守所联系人：</td>
                    <td width="100px">
                        <input  class="mini-textbox" required="true" emptyText="请输入看守所联系人" id="Receiver" name="Receiver"
                                value="${username!''}" />
                    </td>
                </tr>
                <tr>
                    <td class="discell">看守所手机号码：</td>
                    <td>
                        <input  class="mini-textbox"  emptyText="请输入手机号码" id="ReceiverPhone" name="ReceiverPhone"
                                onblur="checkPhone(2)" value="${phone!''}" />
                    </td>
                    <td class="discell">看守所固话：</td>
                    <td width="100px">
                        <input class="mini-textbox"  emptyText="请输入固定电话" id="ReceiverTel" name="ReceiverTel"
                               onblur="checkPhone(1)" value="${tel!''}" />
                    </td>
                </tr>
            <#else >
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>社矫联系人：</td>
                    <td width="100px">
                        <input  class="mini-textbox" required="true" emptyText="请输入社矫联系人" id="Receiver" name="Receiver"
                                value="${username!''}" />
                    </td>
                </tr>
                <tr>
                    <td class="discell">社矫手机号码：</td>
                    <td>
                        <input  class="mini-textbox"  emptyText="请输入手机号码" id="ReceiverPhone" name="ReceiverPhone"
                                onblur="checkPhone(2)" value="${phone!''}" />
                    </td>
                    <td class="discell">社矫固话：</td>
                    <td width="100px">
                        <input class="mini-textbox"  emptyText="请输入固定电话" id="ReceiverTel" name="ReceiverTel"
                               onblur="checkPhone(1)" value="${tel!''}" />
                    </td>
                </tr>
            </#if>
            <input id="fhfs" name="fhfs" class="mini-hidden"   value="${fhfs}"/>
            <#if fhfs =='监狱送回'>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>送回时间：</td>
                    <td >
                        <input  class="mini-datepicker" nullValue="null" format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm" showTime="true"
                                showOkButton="true" showClearButton="false" allowInput="true" required="true" emptyText="请输入送回时间" id="ReturnTime"
                                name="ReturnTime" />
                    </td>
                    <td class="discell"><font color="#dc143c">*</font>送回地点：</td>
                    <td width="100px">
                        <input  class="mini-textbox" required="true" emptyText="请输入送回地点" id="ReturnPlace" name="ReturnPlace" />
                    </td>
                </tr>
            <#elseif fhfs == '人员自返'>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>返回时间：</td>
                    <td >
                        <input  class="mini-datepicker" nullValue="null" format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm" showTime="true"
                                showOkButton="true" showClearButton="false" allowInput="false" required="true" emptyText="请输入送回时间" id="ReturnTime"
                                name="ReturnTime" />
                    </td>
                    <td class="discell">返回地点：</td>
                    <td width="100px">
                        <input  class="mini-textbox"  emptyText="请输入送回地点" id="ReturnPlace" name="ReturnPlace" />
                    </td>
                </tr>
            <#else >
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>接回时间：</td>
                    <td >
                        <input  class="mini-datepicker" nullValue="null" format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm" showTime="true"
                                showOkButton="true" showClearButton="false" allowInput="false" required="true" emptyText="请输入接回时间" id="ReturnTime"
                                name="ReturnTime" />
                    </td>
                    <td class="discell"><font color="#dc143c">*</font>接回地点：</td>
                    <td width="100px">
                        <input  class="mini-textbox" required="true" emptyText="请输入接回地点" id="ReturnPlace" name="ReturnPlace" />
                    </td>
                </tr>
            </#if>
            <tr>
                <td></td>
                <td>
                    <a style="margin-bottom: 10px;" class="mini-button" iconCls="fa-save" onclick="sendMessage()">发送</a>
                </td>
                <td>
                    <a style="margin-bottom: 10px;" class="mini-button" iconCls="fa-refresh" onclick="getDialogList()">刷新</a>
                </td>
                <td></td>
            </tr>
        </table>
    </div>
</form>

<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");
    var priNum = $('#priNum').val();

    function sendMessage() {
        var Receiver = mini.get('Receiver');
        var ReceiverTel = mini.get('ReceiverTel');
        var ReceiverPhone = mini.get('ReceiverPhone');
        var ReturnTime = mini.get('ReturnTime');
        var ReturnPlace = mini.get('ReturnPlace');
        // 验证表单必填项
        form.validate();
        if (form.isValid() == false) {
            return;
        }
        var newPhone = checkTelAndPhone(ReceiverTel.getValue(),ReceiverPhone.getValue());
        var flag = newPhone['flag'];
        var kflag = newPhone['kflag'];
        if ('-1' === kflag) {
            mini.alert("请至少输入一个联系方式");
            return;
        }
        if (flag) {
        } else {
            mini.alert("手机号码或固话有误，请重填");
            return;
        }
        // 获取输入框的值
        var liaisonMan = Receiver.getValue();
        var liaisonTel = ReceiverTel.getValue();
        var liaisonPhone = ReceiverPhone.getValue();
        var takebackTime = ReturnTime.getValue();
        var takebackAddress = ReturnPlace.getValue();
        // 对话框中追加对话信息
        var sendMessage = '<li class="currentUser-wrap">\n' +
            '                <div>监狱</div>\n' +
            '                <ul>\n' +
            '                    <li>联系人：' + liaisonMan + '</li>\n' +
            '                    <li>手机号码：' + liaisonPhone + '</li>\n' +
            '                    <li>固话：' + liaisonTel + '</li>\n' +
            '                    <li>接回时间：' + ReturnTime.getFormValue() + '</li>\n' +
            '                    <li>接回地点：' + takebackAddress + '</li>\n' +
            '                </ul>\n' +
            '            </li>';
        $('.dialog-box').append(sendMessage);
        $("#editform").scrollTop($("#editform")[0].scrollHeight);

        var postData = {
            priNum: priNum,
            liaisonMan: liaisonMan,
            liaisonPhone: liaisonPhone + "|" +liaisonTel,
            takebackTime: takebackTime,
            takebackAddress: takebackAddress,
            message: ""
        };
        postData = mini.encode(postData);
        $.ajax({
            url: '/azbj/yazgl/xj/hz/savemessage',
            type: 'POST',
            datatype: 'json',
            data: {data: postData},
            success: function (data) {
                Receiver.setValue(data.data.userDTO.username);
                ReceiverTel.setValue(data.data.userDTO.telphone);
                ReceiverPhone.setValue(data.data.userDTO.phone);
                ReturnTime.setValue();
                ReturnPlace.setValue();
                msg.setValue();
                // 发送成功后获取所有对话记录
                getDialogList();
            },
            error: function (status) {
                mini.alert("发送异常")
            }
        })
    }

    function getDialogList() {
        var dialogStr = '';
        var fhfs = mini.get("fhfs").getValue();
        $.ajax({
            url: '/azbj/xj/hz/listMessages?priNum=' + priNum,
            type: 'GET',
            datatype: 'json',
            success: function (data) {
                data = JSON.parse(data);
                if (data.length) {
                    // 会话方标识1监狱,2司法所,3看守所,5社矫
                    for (var i = 0, len = data.length; i < len; i++) {
                        if (1 == data[i].ownerFlag) {
                            if (fhfs === '监狱送回') {
                                dialogStr += '<li class="currentUser-wrap">';
                                dialogStr += '<div><span class="send-time">' + data[i].createTime + '</span>' + data[i].sendName + '</div>';
                                dialogStr += '<ul>';
                                dialogStr += '<li>联系人：' + data[i].liaisonMan + '</li>';
                                dialogStr += '<li>监所手机号码：' + data[i].liaisonPhone + '</li>';
                                dialogStr += '<li>监所固话：' + data[i].liaisonTel + '</li>';
                                dialogStr += '<li>送回时间：' + data[i].takebackTime + '</li>';
                                dialogStr += '<li>送回地点：' + data[i].takebackAddress + '</li>';
                                dialogStr += '</ul>';
                                dialogStr += '</li>';
                            }else if (fhfs === '人员自返') {
                                dialogStr += '<li class="currentUser-wrap">';
                                dialogStr += '<div><span class="send-time">' + data[i].createTime + '</span>' + data[i].sendName + '</div>';
                                dialogStr += '<ul>';
                                dialogStr += '<li>联系人：' + data[i].liaisonMan + '</li>';
                                dialogStr += '<li>监所手机号码：' + data[i].liaisonPhone + '</li>';
                                dialogStr += '<li>监所固话：' + data[i].liaisonTel + '</li>';
                                dialogStr += '<li>返回时间：' + data[i].takebackTime + '</li>';
                                dialogStr += '<li>返回地点：' + data[i].takebackAddress + '</li>';
                                dialogStr += '</ul>';
                                dialogStr += '</li>';
                            } else {
                                dialogStr += '<li class="currentUser-wrap">';
                                dialogStr += '<div><span class="send-time">' + data[i].createTime + '</span>' + data[i].sendName + '</div>';
                                dialogStr += '<ul>';
                                dialogStr += '<li>联系人：' + data[i].liaisonMan + '</li>';
                                dialogStr += '<li>监所手机号码：' + data[i].liaisonPhone + '</li>';
                                dialogStr += '<li>监所固话：' + data[i].liaisonTel + '</li>';
                                dialogStr += '<li>接回时间：' + data[i].takebackTime + '</li>';
                                dialogStr += '<li>接回地点：' + data[i].takebackAddress + '</li>';
                                dialogStr += '</ul>';
                                dialogStr += '</li>';
                            }
                        } else if (3 == data[i].ownerFlag) {
                            dialogStr += '<li class="currentUser-wrap">';
                            dialogStr += '<div><span class="send-time">' + data[i].createTime + '</span>' + data[i].sendName + '</div>';
                            dialogStr += '<ul>';
                            dialogStr += '<li>联系人：' + data[i].liaisonMan + '</li>';
                            dialogStr += '<li>看守所手机号码：' + data[i].liaisonPhone + '</li>';
                            dialogStr += '<li>看守所固话：' + data[i].liaisonTel + '</li>';
                            dialogStr += '<li>接回时间：' + data[i].takebackTime + '</li>';
                            dialogStr += '<li>接回地点：' + data[i].takebackAddress + '</li>';
                            dialogStr += '</ul>';
                            dialogStr += '</li>';
                        } else if (5 == data[i].ownerFlag) {
                            dialogStr += '<li class="currentUser-wrap">';
                            dialogStr += '<div><span class="send-time">' + data[i].createTime + '</span>' + data[i].sendName + '</div>';
                            dialogStr += '<ul>';
                            dialogStr += '<li>联系人：' + data[i].liaisonMan + '</li>';
                            dialogStr += '<li>社矫手机号码：' + data[i].liaisonPhone + '</li>';
                            dialogStr += '<li>社矫固话：' + data[i].liaisonTel + '</li>';
                            dialogStr += '<li>接回时间：' + data[i].takebackTime + '</li>';
                            dialogStr += '<li>接回地点：' + data[i].takebackAddress + '</li>';
                            // dialogStr += '<li>备注：' + ((data[i].takebackAddress === null) ? "" : data[i].takebackAddress) + '</li>';
                            dialogStr += '</ul>';
                            dialogStr += '</li>';
                        } else if (2 == data[i].ownerFlag) {
                            if("${localCode!''}" == "140000"){
                                if(null == data[i].message) {
                                    data[i].message="";
                                }
                                dialogStr += '<li>';
                                dialogStr += '<div><span class="send-time">' + data[i].createTime + '</span>' + data[i].name + '司法所</div>';
                                dialogStr += '<ul>';
                                dialogStr += '<li>联系人：' + data[i].liaisonMan + '</li>';
                                dialogStr += '<li>联系电话：' + data[i].liaisonPhone + '</li>';
                                dialogStr += '<li>备注：' + data[i].message + '</li>';
                                dialogStr += '</ul>';
                                dialogStr += '</li>';
                            } else {
                                dialogStr += '<li>';
                                dialogStr += '<div>' + data[i].name + '司法所<span class="send-time">' + data[i].createTime + '</span></div>';
                                dialogStr += '<ul>';
                                dialogStr += '<li>联系人：' + data[i].liaisonMan + '</li>';
                                dialogStr += '<li>司法所手机号码：' + data[i].liaisonPhone + '</li>';
                                dialogStr += '<li>内容：' + data[i].message + '</li>';
                                dialogStr += '</ul>';
                                dialogStr += '</li>';
                            }
                        }
                    }
                } else {
                    dialogStr = "<div style='padding: 50px 0 0;text-align: center;font-size: 18px;'>暂无回执消息</div>"
                }
                $('.dialog-box').html(dialogStr);
                $("#editform").scrollTop($("#editform")[0].scrollHeight);
            }
        })
    }

    //电话号码的验证
    function checkPhone(e) {
        var phone = mini.get("ReceiverPhone").getValue();
        var telPhone = mini.get("ReceiverTel").getValue();
        if (e == '1') {
            if(!validateTel(telPhone)) {
                mini.alert("固定电话有误，请重填");
            }
        }
        if (e == '2') {
            if(!validatePhone1(phone)) {
                mini.alert("手机号码有误，请重填");
            }
        }
    }

    $(function () {
        getDialogList()
    })
</script>
</body>
</html>